package interview;

import java.util.Map;

public class First {

    /**
     * 文本替换
     *
     * @param content 用于被替换的文本
     * @param values  需要被替换的键值对
     * @return 返回被替换后的信息
     */
    public static String replace(String content, Map<String, String> values) {
        StringBuffer stringBuffer = new StringBuffer(content);
        //替换
        for (String key : values.keySet()) {
            StringBuffer replaceBuffer = new StringBuffer("\\{\\{").append(key).append("\\}\\}");
            stringBuffer = new StringBuffer(stringBuffer.toString().replaceAll(replaceBuffer.toString(), values.get(key)));
        }
        return stringBuffer.toString();
    }


}
